package LinksService

import (
	"database/sql"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"seawolf-admin-go/internal/request/BaseReq"
	"seawolf-admin-go/utility/db"
	"seawolf-admin-go/utility/response"
)

func Info(r *ghttp.Request, req *BaseReq.I) *response.JsonResponse {
	ctx := r.GetCtx()
	obj := db.GetUnSafaTable(ctx, req.TableName).Handler(db.SoftDeleteHandler).WherePri(
		"id",
		req.Id,
	)
	// 过滤字段
	if len(req.InfoIgnoreProperty) > 0 {
		obj.Fields(obj.GetFieldsExStr(req.InfoIgnoreProperty))
	}
	res, err := obj.One()
	if err != nil {
		if err != sql.ErrNoRows {
			// 非 结果为空
			return response.FailByRequestMessage(nil, err.Error())
		}
	}
	result := res.Map()
	PhotoPreFixTmp, err := g.Cfg().Get(ctx, "upload.PhotoPreFix", "")
	if err == nil {
		result["photo_base_url"] = PhotoPreFixTmp.String()
	}
	return response.SuccessByRequestMessageData(nil, "获取成功",
		result)
}
